home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE20 / CONSTRUC / THREAD1.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-11  |  873 b   |  42 lines

  1. unit thread1;
  2. interface
  3. uses
  4.   Classes, StdCtrls, SysUtils;
  5.  
  6. type
  7.   TFirstThread = class(TThread)
  8.   public
  9.     CountLabel: TLabel;
  10.     Synchrone,MaxCounter,Counter: LongInt;
  11.     constructor Create(MaxCount,Sync: LongInt; Count: TLabel);
  12.     procedure Execute; override;
  13.     procedure UpdateCounter;
  14.   end;
  15.  
  16. implementation
  17.  
  18. constructor TFirstThread.Create(MaxCount,Sync: LongInt; Count: TLabel);
  19. begin
  20.   inherited Create(False);
  21.   CountLabel := Count;
  22.   MaxCounter := MaxCount;
  23.   Synchrone := Sync;
  24.   Counter := 0
  25. end;
  26.  
  27. procedure TFirstThread.Execute;
  28. begin
  29.   while (Counter < MaxCounter) and not Terminated do
  30.   begin
  31.     Inc(Counter);
  32.     if (Counter mod Synchrone) = 0 then Synchronize(UpdateCounter)
  33.   end
  34. end;
  35.  
  36. procedure TFirstThread.UpdateCounter;
  37. begin
  38.   CountLabel.Caption := Format('%d/%d',[Counter, MaxCounter])
  39. end;
  40.  
  41. end.
  42.